﻿using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;

namespace ManagementPlatform.Utillity.SwaggerExpr
{
    public static class SwaggerConfig
    {
      public  static void StaticSwaggerServerConfig(this WebApplicationBuilder webApplicationBuilder)
        {

            webApplicationBuilder.Services.AddSwaggerGen(opt =>
            {
                //筛选swagger 忽略的字段 需要标记[JsonIgnore]但并无卵用。。。。鸡肋
                opt.OperationFilter<SwaggerOperationFilter>();
                typeof(ApiVersion).GetEnumNames().ToList().ForEach(v =>
                {
                    opt.SwaggerDoc(v, new OpenApiInfo()
                    {

                        Title = $"通用管理后台API文档",
                        Version = v,
                        Description = $"通用版本后台管理系统{v}"
                    });
                });
                var swaggerFileXml = Path.Combine(AppContext.BaseDirectory, "ManagementPlatform.xml");
                opt.IncludeXmlComments(swaggerFileXml, true);

            });
        }

      public static void StaticSwaggerAppConfig(this WebApplication webApplication)
      {
          webApplication.UseSwaggerUI(opt =>
          {

              foreach (var version in typeof(ApiVersion).GetEnumNames())
              {
                  opt.SwaggerEndpoint($"/swagger/{version}/swagger.json", $"api{version}版本");
              }
          });
        }
    }
}
